var course_box_t={};
var growth_interval = 30;
//var growth_rate = 5;
var growth_rate = 30;
var max_h = 210;
var min_h = 115;
var timing = 0;
var reset_all_t;
var current_box = "";
var last_box = "";

//------------------------------------



//-----------------------------------

function checktime () {
	var date1 = new Date();
	var milliseconds1 = date1.getTime();
	var j=0;
	for (i=0; i < 1000000; i++) j++;
	var date2 = new Date();
	var milliseconds2 = date2.getTime();
    
	var difference = milliseconds2 - milliseconds1;
	return difference; 
}

function is_child_of(parent, child) {
	if( child != null ) {			
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {				
		current_mouse_target 			 = event.toElement;
	} else if( event.relatedTarget ) {				
		current_mouse_target 			 = event.relatedTarget;
	}
	if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}

//var growth_rate = checktime ();
//if (growth_rate > 20) growth_rate = 20;
//var growth_loop = 0;


//while (((growth_rate==0)||(growth_rate > 100))&&(growth_loop<3)) {
//	growth_loop++;
//	growth_rate = checktime ();
	//alert(growth_rate)
//}
//if (growth_rate>100) grow_rate=20;


function grow_box (id) {
	
	var box_top = "0px";
	if ($("#" + id).attr("level") == 1) box_top = "-100px"
	
	$("#" + id).animate ({
		height: max_h,
		top: box_top
	},500);
	
	
	box_top = "0px";
	if ($("#" + id).attr("level") == 1) box_top = "100px"
		
	var partner_id = $("#" + id).attr("partner");
	$("#" + partner_id).animate ({
		height: "20px",
		top: box_top
	},500);
	
	
	/*
	var box = document.getElementById(id);
	var partner_id = box.getAttribute("partner");
	var partner_box = document.getElementById(partner_id);
	clearTimeout(course_box_t[id]);
	clearTimeout(course_box_t[partner_id]);
	
	var box_contents =  document.getElementById(id + "_contents");
	var partner_box_contents =  document.getElementById(partner_id + "_contents");
	
	var box_level = box.getAttribute("level");
	var partner_box_level = partner_box.getAttribute("level");
	var partner_box_top = parseInt(partner_box.style.top);
	
	var h = parseInt(box.style.height) + growth_rate;
	
	if (h < max_h) {
		if (box_level==1) box.style.top = parseInt(box.style.top) - growth_rate + "px";
		if ((partner_box_level==1)&& (partner_box_top < min_h +5 )) {
			partner_box.style.top = partner_box_top + growth_rate + "px";
			
		}
		box.style.height = h + "px";
		
		partner_box.style.height = parseInt(partner_box.style.height) -growth_rate + "px";
		course_box_t[id] = setTimeout ( "grow_box ('" + id + "')", growth_interval );
	}
	*/
}

function shrink_box (id) {
	var box = document.getElementById(id);
	var partner_id = box.getAttribute("partner");
	var partner_box = document.getElementById(partner_id);
	
	var box_contents =  document.getElementById(id + "_contents");
	var partner_box_contents =  document.getElementById(partner_id + "_contents");
	
	var box_level = box.getAttribute("level");
	var partner_box_level = partner_box.getAttribute("level");
	
	var h = parseInt(box.style.height) - growth_rate;
	clearTimeout(course_box_t[id]);
	clearTimeout(course_box_t[partner_id]);
	if (h > min_h) {
		if (box_level==1) box.style.top = parseInt(box.style.top) + growth_rate + "px";
		if (partner_box_level==1) partner_box.style.top = parseInt(partner_box.style.top) - growth_rate + "px";
		box.style.height = h + "px";
		//box_contents.style.height = box.style.height;
		
		partner_box.style.height = parseInt(partner_box.style.height)  + growth_rate + "px";
		//partner_box_contents.style.height = partner_box.style.height;
		//box.style.zIndex = 500;
		course_box_t[id] = setTimeout ( "shrink_box ('" + id + "')", growth_interval );
	}
	
}

function clear_queues () {
	$("#s1_box").stop();
	$("#s2_box").stop();
	$("#s3_box").stop();
	$("#s4_box").stop();
	$("#s5_box").stop();
	$("#s6_box").stop();
}

function show_course_box(id) {
	
	//console.log("Fired by " + id)
	//alert(id);
	//if ($("#" + id).attr("level") == 1) box_top = "-100px"
	
	/*
    for (i=1;i<=6;i++) {
    	//if ($("#s" + i + "_box").queue("fx").length > 0) 
    		$("#s" + i + "_box").clearQueue("fx");

    	if (i!=id)$("#s" + i + "_box").animate ({height: min_h},200);
    }*/

	switch (id) {
	case 0: 
		clear_queues ();
		$("#s1_box").animate ({height: min_h, top: "0px"},200);
		$("#s2_box").animate ({height: min_h, top: "0px" },200);
		$("#s3_box").animate ({height: min_h, top: "0px" },200);
		$("#s4_box").animate ({height: min_h, top: "0px" },200);
		$("#s5_box").animate ({height: min_h, top: "0px" },200);
		$("#s6_box").animate ({height: min_h, top: "0px" },200);
		break;	
	case 1: 
		clear_queues ();
			$("#s1_box").animate ({height: max_h, zIndex:1  },200);
			$("#s2_box").animate ({height: min_h, top: "0px"},200);
			$("#s3_box").animate ({height: min_h, top: "0px" },200);
			$("#s4_box").animate ({height: "20px", top:"100px" },200);
			$("#s5_box").animate ({height: min_h, top: "0px" },200);
			$("#s6_box").animate ({height: min_h, top: "0px" },200);
			break;
	case 2: 
		clear_queues ();
		$("#s1_box").animate ({height: min_h, top: "0px" },200);
		$("#s2_box").animate ({height: max_h, zIndex:1 },200);
		$("#s3_box").animate ({height: min_h, top: "0px" },200);
		$("#s4_box").animate ({height: min_h, top: "0px" },200);
		$("#s5_box").animate ({height: "20px", top:"100px" },200);
		$("#s6_box").animate ({height: min_h, top: "0px" },200);
		break;
	case 3: 
		clear_queues ();
		$("#s1_box").animate ({height: min_h, top: "0px" },200);
		$("#s2_box").animate ({height: min_h, top: "0px" },200);
		$("#s3_box").animate ({height: max_h, zIndex:1 },200);
		$("#s4_box").animate ({height: min_h, top: "0px" },200);
		$("#s5_box").animate ({height: min_h, top: "0px" },200);
		$("#s6_box").animate ({height: "20px", top:"100px" },200);
		break;
	case 4: 
		clear_queues ();
		$("#s1_box").animate ({height: "20px" },200);
		$("#s2_box").animate ({height: min_h, top: "0px" },200);
		$("#s3_box").animate ({height: min_h, top: "0px" },200);
		$("#s4_box").animate ({height: max_h, top: "-100px", zIndex:1 },200);
		$("#s5_box").animate ({height: min_h, top: "0px" },200);
		$("#s6_box").animate ({height: min_h, top: "0px" },200);
		break;
	case 5: 
		clear_queues ();
		$("#s1_box").animate ({height: min_h, top: "0px" },200);
		$("#s2_box").animate ({height: "20px" },200);
		$("#s3_box").animate ({height: min_h, top: "0px" },200);
		$("#s4_box").animate ({height: min_h, top: "0px" },200);
		$("#s5_box").animate ({height: max_h, top: "-100px", zIndex:1 },200);
		$("#s6_box").animate ({height: min_h, top: "0px" },200);
		break;
	case 6: 
		
		$("#s1_box").animate ({height: min_h, top: "0px" },200);
		$("#s2_box").animate ({height: min_h, top: "0px" },200);
		$("#s3_box").animate ({height: "20px" },200);
		$("#s4_box").animate ({height: min_h, top: "0px" },200);
		$("#s5_box").animate ({height: min_h, top: "0px" },200);
		$("#s6_box").animate ({height: max_h, top: "-100px", zIndex:1 },200);
		break;
	}
	/*
	$("#s" + id + "_box").clearQueue("fx");
    $("#s" + id + "_box").animate ({
		height: max_h
	},200);
    
    $(".course_box").clearQueue("fx");
	$(".course_box").animate ({
		height: min_h
	},200);
	
	*/
	/*
	
	//var partner_id = document.getElementById(id).getAttribute("partner");
	//shrink_box (partner_id);
	current_box = id;
	grow_box (id);
	
	var id_number = id.substr(1,1);


	switch (id_number) {
	case "1": case "4":
		//alert (id_number);
		reset_boxes("s2_box");
		reset_boxes("s3_box");
		break;
	case "2": case "5":
		reset_boxes("s1_box");
		reset_boxes("s3_box");
		break;	
	case "3": case "6":
		reset_boxes("s1_box");
		reset_boxes("s2_box");
		break;
	}

	clearTimeout(reset_all_t);
	//reset_all_t = setTimeout ( "reset_all ()", 100 );
	//alert(id_number);
	//reset_class(id);
	//var box = document.getElementById(id);
	
	//box.className = box.className + " info_tall_" + level;
	*/
	//alert(id);
	
	
}


function set_box(id) {
	
	current_box = id;
}
function unset_box() {
	last_box = current_box;
	current_box = -1;
}

function reset_all_non_ie () {
	if(navigator.appName=="Microsoft Internet Explorer") return false;
	reset_all ();
	
}

function reset_all_ie () {
	reset_all ();
}

function reset_all () {
	reset_boxes("s1_box");
	reset_boxes("s2_box");
	reset_boxes("s3_box");
}

function hide_course_box(id,level) {
	//shrink_box (id);
	//reset_class(id);
	//var box = document.getElementById(id);
	//box.className = box.className + " info_short_" + level;
}

function reset_class(id) {
	/*var box = document.getElementById(id);
	box.className = box.className.replace(" info_tall_0", "");
	box.className = box.className.replace(" info_tall_1", "");
	box.className = box.className.replace(" info_short_0", "");
	box.className = box.className.replace(" info_short_1", "");*/
}

function reset_boxes (id) {
	$("#" + id).animate ({
		height: min_h,
		top:"0px"
	},500);
	
	var partner_id = $("#" + id).attr("partner");
	
	$("#" + partner_id).animate ({
		height: min_h,
		top:"0px"
	},500);
	/*
	//growth_rate = 0;
	//while (growth_rate==0) growth_rate = checktime ();
	var rerun = 0;
	var box = document.getElementById(id);
	var partner_id = box.getAttribute("partner");
	var partner_box = document.getElementById(partner_id);
	
	
	clearTimeout(course_box_t[id]);
	clearTimeout(course_box_t[partner_id]);
	
	var box_level = box.getAttribute("level");
	
	var partner_box_level = partner_box.getAttribute("level");
	
	var box_h = parseInt(box.style.height);
	var partner_box_h = parseInt(partner_box.style.height);
	var box_t = parseInt(box.style.top);
	var partner_box_t = parseInt(partner_box.style.top);
	
	if (box_h > min_h) {
		//if (box_level==1) box.style.top = parseInt(box.style.top) + growth_rate + "px";
		box.style.height = box_h - growth_rate + "px";
		//box_contents.style.height = box.style.height;
		rerun = 1;
	} else if (box_h < min_h) {
		//if (box_level==1) box.style.top = parseInt(box.style.top) - growth_rate + "px";
		box.style.height = box_h + growth_rate + "px";
		rerun = 1;
	}
	
	
	
	
	if (partner_box_h > min_h) {
		//if (partner_box_level==1) partner_box.style.top = parseInt(partner_box.style.top) - growth_rate + "px";
		partner_box.style.height = partner_box_h - growth_rate + "px";
		rerun = 1;
	} else if (partner_box_h < min_h) {
		//if (partner_box_level==1) partner_box.style.top = parseInt(partner_box.style.top) - growth_rate + "px";
		partner_box.style.height = partner_box_h + growth_rate + "px";
		rerun = 1;
		
	}
	
	if ((partner_box_level==1) && (parseInt(partner_box.style.top) <0 )) {
		partner_box.style.top = parseInt(partner_box.style.top) + growth_rate + "px";
		rerun = 1;
	} else if ((partner_box_level==1) && (parseInt(partner_box.style.top) > 0 )) {
		partner_box.style.top = parseInt(partner_box.style.top) - growth_rate + "px";
		rerun = 1;
	}
	
	if (box_level == 1) {
		if (box_t < 0 ) {
			box.style.top = parseInt(box.style.top) + growth_rate + "px";
			rerun = 1;
		} else if (box_t > 0 ) {
			box.style.top = parseInt(box.style.top) - growth_rate + "px";
			rerun = 1;
		}
		
	}
	
	var box_contents =  document.getElementById(id + "_contents");
	var partner_box_contents =  document.getElementById(partner_id + "_contents");
	//partner_box_contents.style.height = partner_box.style.height;
	//box_contents.style.height = box.style.height;
	
	
	//console.log(box.style.top);
	if (rerun == 1) course_box_t[id] = setTimeout ( "reset_boxes ('" + id + "')", growth_interval );
}

function normal_course_box (id) {
  //clearTimeout(course_box_t[id]);
  //shrink_box (id);
	reset_boxes (id);
	*/
}


function checkmouseout(id, e)
{ 
	if (window.event) e = window.event; 
	var clicked_element = e.srcElement? e.srcElement : e.target; 
	//console.log(e.target.id);
	
	}



document.getElementById("s1_box_contents").style.visibility="visible";
document.getElementById("s2_box_contents").style.visibility="visible";
document.getElementById("s3_box_contents").style.visibility="visible";
document.getElementById("s4_box_contents").style.visibility="visible";
document.getElementById("s5_box_contents").style.visibility="visible";
document.getElementById("s6_box_contents").style.visibility="visible";
